package com.yb.module.model.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yb.framework.core.base.BaseMapper;
import com.yb.framework.core.base.BaseServiceImpl;
import com.yb.framework.core.utils.SecurityUtil;
import com.yb.framework.core.utils.SnowflakeIdWorker;
import com.yb.framework.neo4j.service.Neo4jService;
import com.yb.module.model.domain.ModelShapeParam;
import com.yb.module.model.mapper.ModelShapeParamMapper;
import com.yb.module.model.service.ModelShapeParamService;

@Service
public class ModelShapeParamServiceImpl extends BaseServiceImpl<ModelShapeParam> implements ModelShapeParamService {

	@Autowired
	private Neo4jService neo4jService;
	@Autowired
	private ModelShapeParamMapper modelShapeParamMapper;
	
	@Override
	protected BaseMapper<ModelShapeParam> getMapper() {
		return modelShapeParamMapper;
	}

	@Override
	public int insertParam(ModelShapeParam modelShapeParam) {
		// TODO Auto-generated method stub
		long id = SnowflakeIdWorker.getInstance().getId();
		neo4jService.createParamNode("param", String.valueOf(id), modelShapeParam.getName(), 
				"shape", String.valueOf(modelShapeParam.getShapeId()));
		
		modelShapeParam.setId(id);
		modelShapeParam.setCreateBy(SecurityUtil.getUsername());
		modelShapeParam.setCreateTime(new Date());
		return modelShapeParamMapper.insert(modelShapeParam);
	}
	
	@Override
	public int updateParam(ModelShapeParam modelShapeParam) {
		// TODO Auto-generated method stub
		neo4jService.updateNode("param", String.valueOf(modelShapeParam.getId()), modelShapeParam.getName());
		
		modelShapeParam.setUpdateBy(SecurityUtil.getUsername());
		modelShapeParam.setUpdateTime(new Date());
		return modelShapeParamMapper.update(modelShapeParam);
	}

	@Override
	public int deleteParam(Long[] ids) {
		// TODO Auto-generated method stub
		for (Long id : ids) {
			neo4jService.deleteNode("param", String.valueOf(id));
		}
		
		return modelShapeParamMapper.deleteListByIds(ids);
	}
}